package com.chat.datea.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.chat.datea.R;
import com.chat.datea.bean.SingerEntity;

import java.util.List;

/**
 * Created by dllo on 15/10/26.
 * 发现页面点击男歌手跳转 适配器
 * 王锦予
 */
public class Fragment_man_ListView_Adapter extends BaseAdapter {
    private List<SingerEntity.ResultEntity.ItemsEntity> data;
    private SingerEntity singerEntity;
    private Context context;

    public Fragment_man_ListView_Adapter(Context c, SingerEntity entities){
        this.context = c;
        this.singerEntity = entities;
        data = singerEntity.getResult().getItems();

    }


    @Override
    public int getCount() {
        return data != null && data.size() > 0 ? data.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return data != null && data.size() > 0 ? data.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null){
            holder = new ViewHolder();
            //通过布局加载器来加载布局文件
            convertView = LayoutInflater.from(context).inflate(R.layout.fragment_man_jump_item, null);
            //初始化控件
            holder.man_singer_btn = (ImageView) convertView.findViewById(R.id.man_singer_btn);
            holder.man_singer_title = (TextView) convertView.findViewById(R.id.man_singer_title);
            //设置标签
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        //设置组件
        holder.man_singer_title.setText(singerEntity.getResult().getItems().get(position).getArtist_name());

            return convertView;
    }
    //缓存组件
    public class ViewHolder{
        private TextView  man_singer_title;
        private ImageView man_singer_btn;
    }

}
